JSON Compilation Database
Synchronization can be carried out using a JSON Compilation Database file, a JSON based data format that is used by the Clang compiler. The Compilation Database contains the working directory, compile command and include paths required to compile each translation unit.
A single JSON Compilation Database entry has this format:
"directory": "/home/steve/Temp",
"command": "g++ -std=c++11 -I . enum.cpp",
"file": "/home/steve/Temp/enum.cpp"
There are various build systems that support the generation of JSON Compilation Databases including Clang, CMake (version 2.8.5 onwards) and Ninja(1.2 onwards). This manual will not cover the generation of the databases with all build systems, however in the case of CMake, all that is required is the following flag to be added to the build:
If your build systems do not currently support this generation, there are many tools that can intercept the compilation process and generate a corresponding compilation database. One of the more prominent tools is Bear1, and allows for simple usage:
which generates a compile_commands.json
file in the current directory.